﻿<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<%
	String cpath=request.getContextPath();
%>
 <HEAD>
 
  <TITLE> New Document </TITLE>
 </HEAD>
 <style> 
 	a{text-decoration:none; font-weight:bold} 	
 	.graybg {background:url(../frame/images/btn_8.jpg); margin:0 1px;}
 	.graybg a{color:#fff;}
 	.redbg{background:url(../frame/images/btn_9.jpg); margin:0 1px;}
 	.redbg a{color:#520408;}
 </style>
 <BODY style="margin:0px; padding:2px 0 0 5px;background-color: #EBEBE3" onselectstart="return false;" oncontextmenu="return 

false;" >
  <table border="0" cellspacing="0" cellpadding="0" id="mytable">
	<tr id="mytr" valign="top"></tr>
  </table>
 </BODY>
</HTML>

<script language="javascript">
<!--     
var len = document.getElementById("mytable").cells.length;
var lastid;
var maxtab = 8;

var rootParam=null;//第一个
var currentParam=null;//当前
var finalParma=null;

function winParam(){
	this.id;
	this.obj;
	this.lastParam;
	this.nextParam;
	this.ct=0;//子节点数
	this.paId;//父节点id
}

//添加一栏目标签
function addTd(name,id){
	var tableNode = document.getElementById("mytable");
	var trNode = document.getElementById("mytr");
	//所有窗口关掉后len不等于0
	if(len!=mytable.cells.length){
		len=0;
	}
	//把tdNode添加到第几列（从0开始）
	var tdNode = trNode.insertCell(len);
	tdNode.id = id;
	tdNode.value = id;
	tdNode.height=40;
	//创建一个小table嵌入到tdNode
	var stb=document.createElement("table");
	tdNode.appendChild(stb);
	stb.id = 'stb'+id;
	//小table的背景图片
	stb.className="graybg";
	//小table里面插入一行
	var str=stb.insertRow(0);
	//一行里面放两个小td
	var std1=str.insertCell(0);
	var std2=str.insertCell(1);	
	std1.style.fontColor="#333";	
	std1.style.fontSize="12px";
	std1.height=24;	
	std1.width=74;
	std2.width=5;
	std1.align="center";
	std1.valign="middle";
	//创建一个点击标签改变窗口的超链接
	var link = document.createElement("<a href='javascript:checkedTab(\""+id+"\")'></a>");
	link.id = 'a'+id;
	link.title = name;
	//把超链接放到第一个小td里面
	std1.appendChild(link);
	//因为标签里面存放的名字有限，所以去前5位后面用"..."代替
	if(name.length>5){
	   name=name.substring(0,4)+"...";
	}
	//把名字放到超链接里面去
	var text=document.createTextNode(name);
	link.appendChild(text);
	//创建一个删除超链接
	var delLink = document.createElement("<a href='javascript:delTag(\""+id+"\")'></a>");
	//放到第二个小td里面
	std2.appendChild(delLink);
	//把删除图片方放到删除的超链接里面
	var delText=document.createElement("<img src='../frame/images/del.gif' border='0'>");
	delLink.appendChild(delText);
	len++;
}
//删除一列
function delTd(id){
	var tableNode = document.getElementById("mytable");
	var trNode = document.getElementById("mytr");
	trNode.removeChild(document.getElementById(id));
	len--;
}
//新建一个标签后调用一个新建窗口
function newTab(url,name,id,obj,pa){
	//如果栏目标签存在直接显示
	if(mytable.cells.length!=0){
		if(document.getElementById(id)!=null){
			parent.document.frames["mian"].showWindow(id,lastid);
			lastid = id;
			return;
		}
	}
	//最多能打开的窗口数
	if(len==maxtab){
		alert("由于打开窗口太多，请您关掉一些再进行此操作!!");
		return;
	}
	//新建一个标签
    addTd(name,id);
   
   
    var win = new winParam();
    win.id = id;
    win.obj = obj;
    win.paId=pa;
    if(len==1){
    	win.lastParam = null;
    	win.nextParam = null;
    	rootParam = win;
    	finalParma = win;
    	currentParam = win;
    }else{
   		win.lastParam = finalParma;
   		win.lastParam.nextParam = win;
   		win.nextParam = null;
   		currentParam = win;	
   		finalParma = win;
    }
    addChildWin(win.paId);
	parent.document.frames["mian"].newWindow(url,id,lastid);
	lastid = id;
}

//测试方法1
function getTable(rt){
	var str="";
	while(rt!=null){
		str+=rt.id+"--"+rt.obj;
		if(rt.lastParam!=null){
			str+=" last:"+rt.lastParam.id;
		}
		if(rt.nextParam!=null){
			str+=" next:"+rt.nextParam.id;
		}
		str+="\n";
		rt=rt.nextParam;
	}
	return str;
}
//点击标签显示窗口
function checkedTab(id){
	parent.document.frames["mian"].showWindow(id,lastid);
	lastid = id;
}
//点击删除关闭窗口
function delTag(id){
	try{
		var paId="";
		var tmpParam = rootParam;
		while(tmpParam!=null){
			if(tmpParam.id == id){
				if(tmpParam.ct>0){
					alert("有未关闭的子窗口，不能执行此操作!");
					return;
				}
				if(tmpParam.lastParam ==null){//为第一个
					rootParam = tmpParam.nextParam;
					if(tmpParam.nextParam!=null){
						tmpParam.nextParam.lastParam = null;
					}
				}if(tmpParam.nextParam ==null){//为最后一个
					if(tmpParam.lastParam!=null){
						tmpParam.lastParam.nextParam = null;
						finalParma = tmpParam.lastParam;
					}
				}if(tmpParam.lastParam !=null&&tmpParam.nextParam!=null){
					tmpParam.lastParam.nextParam = tmpParam.nextParam;
					tmpParam.nextParam.lastParam = tmpParam.lastParam;
				}
				delChildWin(tmpParam.paId);
				tmpParam = null;
				break;
			}
			tmpParam = tmpParam.nextParam;
		}
		delTd(id);
		var newlastid=parent.document.frames["mian"].delWindow(id,lastid);
		lastid =newlastid;
	}
	catch(ex){
		alert("title.delTag:"+ex.name+":"+ex.message);
	}
}
//改变上一窗口的背景图片
function changeLastPicture(lastid){
	if(document.getElementById('stb'+lastid)!=null){
		document.getElementById('stb'+lastid).className="redbg";
	}
}
//改变当前窗口的图片
function changeNowPicture(id){
	if(document.getElementById('stb'+id)!=null){
		document.getElementById('stb'+id).className="graybg";
	}
}

function getLastWindow(id){
	var tmpParam=rootParam;
	while(tmpParam!= null){
		if(tmpParam.id == id){
			return tmpParam.obj;
		}
		tmpParam=tmpParam.nextParam;
	}
}
function addChildWin(paid){//增加子节点时，将父节点ct加1
	if(paid!=null){
		var tmpParam=rootParam;
		while(tmpParam!= null){
			if(tmpParam.id == paid){
				tmpParam.ct++;
			}
			tmpParam=tmpParam.nextParam;
		}	
	}
}
function delChildWin(paid){//删除子节点时，将父节点ct减1
	if(paid!=null){
		var tmpParam=rootParam;
		while(tmpParam!= null){
			if(tmpParam.id == paid){
				tmpParam.ct--;
			}
			tmpParam=tmpParam.nextParam;
		}	
	}
}

//测试方法2
function getWinById(id){
	if(id!=null){
		var tmpParam=rootParam;
		while(tmpParam!= null){
			if(tmpParam.id == id){
				return tmpParam;
			}
			tmpParam=tmpParam.nextParam;
		}
		return null;
	}
}
-->
</script>